//
//  ViewController.m
//  CAReplicatorLayerWaveform
//
//  Created by Xwoder on 17/1/30.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import "UIView+ALQuickFrame.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.frame = self.view.bounds;
    replicatorLayer.instanceCount = 25;
    replicatorLayer.instanceTransform = CATransform3DMakeTranslation(20, 0, 0);
    replicatorLayer.instanceDelay = 0.2;
    replicatorLayer.instanceRedOffset = -0.025;
    replicatorLayer.backgroundColor = [UIColor whiteColor].CGColor;
    
    CALayer *layer = [CALayer layer];
    CGFloat layerWidth = 10;
    CGFloat layerHeight = 200;
    CGFloat layerX = 5;
    CGFloat layerY = self.view.height / 2 - layerHeight / 2;
    layer.frame = CGRectMake(layerX, layerY, layerWidth, layerHeight);
    layer.backgroundColor = [UIColor redColor].CGColor;

    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"transform.scale.y";
    animation.duration = 0.5;
    animation.toValue = @(0.5);
    animation.autoreverses = YES;
    animation.repeatCount = MAXFLOAT;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = YES;

    [replicatorLayer addSublayer:layer];
    [self.view.layer addSublayer:replicatorLayer];
    [layer addAnimation:animation forKey:nil];
}

@end
